package com.cyanite.playlv2.widget;

import com.cyanite.playlv2.R;
import com.cyanite.playlv2api.types.VenueCategory;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

public class SearchCategoryAdapter extends BaseAdapter  {
    
    private ArrayList<VenueCategory> mCategories;
    private int mLayoutToInflate;
    private LayoutInflater mInflater;
    
    public SearchCategoryAdapter(Context context,ArrayList<VenueCategory> categories){
        mInflater = LayoutInflater.from(context);
        mLayoutToInflate = R.layout.category_picker_list_item;
        mCategories = categories;
    }

    public int getCount() {
        return mCategories.size();
    }

    public VenueCategory getItem(int position)    {
        return mCategories.get(position);
    }

    public long getItemId(int position)    {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(mLayoutToInflate, null);
            
            holder = new ViewHolder();
            holder.icon = (ImageView) convertView.findViewById(R.id.categoryPickerIcon);
            holder.name = (TextView) convertView.findViewById(R.id.categoryPickerName);
            holder.disclosure = (ImageView) convertView.findViewById(R.id.categoryPickerIconDisclosure);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder)convertView.getTag();
        }
        holder.icon.setImageResource(mCategories.get(position).getIconRes());
        holder.name.setText(mCategories.get(position).getTaskNameRes());
        holder.disclosure.setVisibility(View.GONE);

        return convertView;
    }
    private static class ViewHolder {
        ImageView icon;
        TextView name;
        ImageView disclosure;
    }
}
